How can I put the results of Cursor into String[]. For more detail, please refer to the code below
Posted
by
Hicen
on Stack Overflow
See other posts from Stack Overflow
or by Hicen
Published on 2012-11-07T16:55:07Z
Indexed on
2012/11/07
17:00 UTC
Read the original article
Hit count: 171
public class DisplayCustomersActivity
extends Activity implements Button.OnClickListener
{
private SalesDB sdb;
private ListView lvDCList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.displaycustomers);
lvDCList = (ListView) findViewById(R.id.lvDCList);
sdb = new SalesDB(this);
SQLiteDatabase db = sdb.getReadableDatabase();
Cursor results = db.query(sdb.TABLE_CUSTOMER, new String[] {sdb.CUSTOMER_ID, sdb.CUSTOMER_NAME, sdb.CUSTOMER_GENDER}, null, null, null, null, null);
int resultCount = results.getCount();
String[] customers = new String[resultCount];
if (resultCount == 0 || !results.moveToFirst()) {
customers = null;
} else {
for(int i=0; i<resultCount; i++) {
//Process results to String array here
...
...
results.moveToNext();
}
}
}
© Stack Overflow or respective owner